const Koa = require("koa");
const proxyConfig = require("./proxy");
const https = require('https');
axios.defaults.timeout = 50000; // 设置超时时间为5秒

const httpsAgent = new https.Agent({
    rejectUnauthorized: false
  });
const { default: axios } = require("axios");
const app = new Koa();
app.use(async (ctx) => {
  for (let i = 0; i < proxyConfig.length; i++) {
    const item = proxyConfig[i];
    if (item.match.test(ctx.request.url)) {
      console.log("匹配到", ctx.request.url);
      const html = await axios({
        url:item.proxyPass,
        
        method:'get'
      }).then((v) => v.data).catch(error => {
        console.error("error",error);
      });
      ctx.body = html;
      return;
    }
  }
  console.log("没匹配");
  ctx.body = "ok";
});
app.listen(3001);
